<?php

//process add action wp_head
add_action('wp_head','db_head_init');
function db_head_init()
{
	db_show_html_favicon();
	#Theme urls for Style Picker
	echo "\n <script type='text/javascript'>\n\t";
	echo "var mytheme_urls = {";
	echo "\n \t\tajaxurl:'".admin_url('admin-ajax.php' )."'";
	echo "\n \t\t,url:'".get_site_url()."'";
	echo "\n\t};\n";
	echo " </script>\n";
	
	
}

//process add action wp_footer
add_action('wp_footer','db_footer_init');
function db_footer_init()
{
	db_show_html_back_to_top();
}


// Process show social link page top page
function db_show_html_social_link_page()
{
	global $myoptions;
	$html = '';
	if($myoptions['basic_facebooklink'])
		$html .= '<a href="'.$myoptions['basic_facebooklink'].'"><img src="'.get_bloginfo('template_url').'/images/facebook.png" alt="facebook" /></a>';
	if($myoptions['basic_googlelink'])
		$html .= '<a href="'.$myoptions['basic_googlelink'].'"><img src="'.get_bloginfo('template_url').'/images/google.png" alt="facebook" /></a>';
	if($myoptions['basic_youtobelink'])
		$html .= '<a href="'.$myoptions['basic_youtobelink'].'"><img src="'.get_bloginfo('template_url').'/images/youtube.png" alt="facebook" /></a>';
	if($myoptions['basic_twitterlink'])
		$html .= '<a href="'.$myoptions['basic_twitterlink'].'"><img src="'.get_bloginfo('template_url').'/images/twitter.png" alt="facebook" /></a>';
	
	echo $html;
	unset($html);
}

// Process site favicon
function db_show_html_favicon()
{
	global $myoptions;
	if($myoptions['basic_favicon'])		
		$html = '<link href="'.$myoptions['basic_favicon'].'" rel="shortcut icon" type="image/x-icon" />';
	else 
		$html = '<link href="'.get_bloginfo('template_url').'/favicon.ico" rel="shortcut icon" type="image/x-icon" />';
	echo $html;
	unset($html);
}

// process site logo
function db_show_html_logo()
{
	global $myoptions;
	
	if(is_home() || is_front_page()){
		$open = '<h1>';		
		$end = '</h1>';
	}
	else{
		$open = '';
		$end = '';
	}
		
	
	if($myoptions['basic_logo']){
		$html = $open;
		$html .= '<a href="'.get_bloginfo("home").'"><img src="'.$myoptions['basic_logo'].'" alt="'.get_bloginfo("name").'"/></a>';
		$html .= '<span style="display:none;">'.get_bloginfo('name').'</span>';
		$html .= $end;
	}	
	else{ 
		$html = $open;	
		$html .= '<a href="'.get_bloginfo("home").'"><img src="'.get_template_directory_uri().'/images/logo.png" alt="'.get_bloginfo("name").'"/></a>';
		$html .= '<span style="display:none;">'.get_bloginfo('name').'</span>';
		$html .= $end;
	}
	echo $html;
	unset($html);
}

/**************************************************************************************************************/

// html tren moi template

function db_call_show_html_slideshow()
{
	global $wpdb;
	$html = '
			<div class="container_24 main_container">
			    <div class="grid_24 hp_slideshow">
			        <ul id="myGallery">';
					$sliders = new WP_Query(array('post_type' => 'sliders'));
					if($sliders->have_posts())
					{
						while ($sliders->have_posts())
						{
							$sliders->the_post();
								
							if(has_post_thumbnail())
							{
								$html .= '<li>';
								$html .= get_the_post_thumbnail();
								$html .= '</li>';
							}
						}
					}
					
					$html .= '
					</ul>
			    </div>
			</div>
			';
	return $html;
}


// process slide show big image
function db_show_html_slideshow()
{		
	?>
	<!-- only home page -->
	<!-- Second, add the Timer and Easing plugins -->
	<script type="text/javascript" src="<?php echo get_template_directory_uri();?>/js/jquery.timers-1.2.js"></script>
	<script type="text/javascript" src="<?php echo get_template_directory_uri();?>/js/jquery.easing.1.3.js"></script>

	<!-- Third, add the GalleryView Javascript and CSS files -->
	<script type="text/javascript" src="<?php echo get_template_directory_uri();?>/js/jquery.galleryview-3.0-dev.js"></script>
	<link type="text/css" rel="stylesheet" href="<?php echo get_template_directory_uri();?>/css/jquery.galleryview-3.0-dev.css" />

	<!-- Lastly, call the galleryView() function on your unordered list(s) -->
	<script type="text/javascript">
		$(function(){
			$("#myGallery").galleryView();
		});
	</script>	
	<!-- end only home page -->
	<?php 
	$html = db_callback_mydata("mycache_transient_slideshow","db_call_show_html_slideshow",86400);
	echo $html;
	unset($html);	
}

// process back to top jquery
function db_show_html_back_to_top()
{
	
	$html = "	
			<!--	
			<style type='text/css'>
			#bttop{border:1px solid #4adcff;background:#24bde2;text-align:center;padding:5px;position:fixed;bottom:35px;right:10px;cursor:pointer;display:none;color:#fff;font-size:11px;font-weight:900;}
			#bttop:hover{border:1px solid #ffa789;background:#ff6734;}
			</style>
			-->
			<style type='text/css'>
			#bttop{background: url('".get_template_directory_uri()."/images/scroll.png') no-repeat scroll left 0 transparent;;text-align:center;padding:5px;position:fixed;bottom:35px;right:10px;cursor:pointer;display:none;color:#fff;font-size:11px;font-weight:900; width:46px; height:46px;}
			#bttop:hover{}
			</style>
			<div id='bttop'>&nbsp;</div>						
			";			
	echo $html;
	unset($html);
	?>
	<script type='text/javascript'>$(function(){$(window).scroll(function(){if($(this).scrollTop()!=0){$('#bttop').fadeIn();}else{$('#bttop').fadeOut();}});$('#bttop').click(function(){$('body,html').animate({scrollTop:0},800);});});</script>
	<?php 
}


// process show footer
function db_show_html_footer()
{
	global $myoptions;
	$html = '<div class="bottom_footer">
	            <div class="fleft content_detail">';
	
	if($myoptions['contact-companyname'])
		$html .= '<p><strong>'.$myoptions['contact-companyname'].'</strong></p>';
	
	if($myoptions['contact-adress'])
		$html .= '<p>Địa chỉ : '.$myoptions['contact-adress'].'</p>';
	
	if($myoptions['contact-phone'])
		$html .= '<p>Điện thoại : '.$myoptions['contact-phone'].'</p>';
	
	if($myoptions['contact-fax'])
		$html .= '<p>Fax : '.$myoptions['contact-fax'].'</p>';
	
	if($myoptions['contact-email'])
		$html .= '<p>Email : '.$myoptions['contact-email'].'</p>';
	
	if($myoptions['basic_footer_design'])
		$html .= '<p>Phát triển website : <a href="http://webseo24h.com">'.$myoptions['basic_footer_design'].'</a></p>';
	else
		$html .= '<p style="display:none;">Thiết kế bởi : <a href="http://webseo24h.com">Webseo24h.com</a></p>';
	
	$html .= '
			  </div>
	        </div>
			';
	echo $html;
	unset($html);
}